this.main=function() {
	var tn=this.tablename;
	var eidtform=null;
	var eidtwindow=null;
	var destroyObjs=[];
	var myobject=this;
	var sm = new Ext.grid.CheckboxSelectionModel({
				singleSelect : false
			});
	 var datatypeStore=new Ext.data.SimpleStore({
			fields : [ 'value', 'text' ],
			data : [ [ 's', '字符型' ], [ 'n', '数字型' ], [ 'd', '日期型' ] ]
		});
	var cm = getdicclumncfg1(sm,datatypeStore);
	var dataRecord = Ext.data.Record.create([
			{name : 'columnid',	type : 'string'},
			{name : 'tablecode',	type : 'string'},
			{name : 'name',	type : 'string'},
			{name : 'datatype',	type : 'string'},
			{name : 'datalength',	type : 'string'},
			{name : 'scale',	type : 'string'},
			{name : 'codetype',	type : 'string'},
			{name : 'codeformat',	type : 'string'},
			{name : 'sourcetable',	type : 'string'},
			{name : 'sourcecolumn',	type : 'string'},
			{name : 'nullable',	type : 'string'},
			{name : 'dboprflag',	type : 'string'},
			{name : 'defaultvalue',	type : 'string'},
			{name : 'used',	type : 'string'},
			{name : 'systempretag',	type : 'string'},
			{name : 'filter',	type : 'string'},
			{name : 'cnname',	type : 'string'},
			{name : 'coltype',	type : 'string'}
			]);

	function openwindow(title,url){
		
		 		var record = grid.getSelectionModel().getSelections();
					if (record.length <= 0) {
							Ext.MessageBox.alert('提示', '需要修改的记录');
							return;
						} else if (record.length > 1) {
							Ext.MessageBox.alert('提示', '最多只能选择一行');
							return;				
						}else if (record[0].data.predefine==1) {
							Ext.MessageBox.alert('提示', '系统预设不可编辑！');
							return;				
						}
		 
		 if(eidtwindow!=null){
		 	eidtwindow.setTitle(title);
		 	eidtwindow.actionUrl=url;
			eidtwindow.show();
			eidtform.getForm().reset();
			eidtform.getForm().setValues(record[0].data);
			return;
			}
				  loadForm( basepath+"dic/js/diccolumnform.js",function(form){
				  		eidtform=form;
				  		destroyObjs[0]=form;
				  		eidtwindow = new Ext.Window({
								title : title,
								width : 382,
								closeAction : 'hide',
								plain : true,
								actionUrl:url,
								labelAlign : "right",
								buttonAlign : "center",
								resizable:false,
								modal:true,
								padding:"2px 2px",
								items : [eidtform],
								buttons : [ {text:"保存",
											   handler : function(){
											   	
												   var record = grid.getSelectionModel().getSelections();
												   record[0].data.sourcetable=Ext.getCmp('sourcetableid_'+myobject.menuid).getValue();
												   record[0].data.sourcecolumn=Ext.getCmp('sourcecolumnid_'+myobject.menuid).getValue();
											   		submitFormPanel(eidtform, eidtwindow.actionUrl, function(form,action){
											   			Ext.Msg.alert("提示",action.result.info);
											   		})
											   }
											},
											{text:"关闭",
											   handler : function() {
													eidtwindow.hide();	
											 	}
											}
										  ]
					
						});
				  	destroyObjs[1]=eidtwindow;
					eidtform.getForm().setValues(record[0].data);
					Ext.getCmp('sourcetableid_'+myobject.menuid).getStore().load({
						callback :function(){
							eidtwindow.show();	 
						}
						
					})
					
					
				  },myobject);
		
		}
    
   
	var store = new Ext.data.Store({
			baseParams:{tablename:tn}, 
			 autoLoad : {tablename:tn},
				proxy : new Ext.data.HttpProxy({
						url :basepath+'../sysControl/system/SysDicColumnController/query.do'

						}),

				reader : new Ext.data.JsonReader({
							totalProperty : 'results'
							}, dataRecord)
			});

	var editor = new Ext.ux.grid.RowEditor({
        saveText: '完成',
        cancelText:'取消',
        clicksToEdit:2,
        errorSummary:false,
        onRowDblClick: function(g, rowIndex, e){
        	if(!this.isVisible()){
        		this.startEditing(rowIndex, false);
        		this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
        	}
        },
        listeners:{
        	'beforeedit':function(obj,index){
        		return obj.grid.store.getAt(index).data.systempretag!=1;
        		
        	},
        	'canceledit':function(obj,forced){
        		console.log(obj.record);
        		//if(forced===true)
        		if(obj.record.get('columnid')==null)
        			store.remove(obj.record);
        			        	
        	//	store.reload();
            },
        	'afteredit':function(obj,changes,record,index){
        	
        		obj.isValid();
        		/*var para="systempretag:1";
        		record.fields.each(function(item,index){
        			if(item.name!='systempretag')
        			para+=","+item.name+":"+((record.get(item.name)==""||record.get(item.name)==undefined)?"null":"'"+record.get(item.name)+"'")})
        		submitRow(basepath+'../sysControl/system/SysDicColumnController/merge.do',Ext.util.JSON.decode("{"+para+"}"));*/
        		grid.getView().refresh();
        		
        	},
        	'validateedit':function(obj,changes,record,index){
        		var flag=true;
        	/*Ext.Ajax.request({
			   url: basepath+'../sysControl/system/SysDicColumnController/isUnique.do',
			   method:'post',
			   async:false,
			   success : function(request) {var message = request.responseText;
			   var json=Ext.util.JSON.decode(message)
			   if(json.success==true)
				   flag=true;
			   else{
				   Ext.MessageBox.show({
						title : '操作失败',
						msg : json.info,
						buttons : Ext.Msg.OK,
						icon : Ext.MessageBox.ERROR

					});
				   flag=false;
			   }
			   								},
				failure : function(request) {Ext.Msg.alert("错误", "与后台联系的时候出现了问题");},
			   headers: {
			       'my-header': 'foo'
			   },
			   params: {
				   tablecode:obj.get(2).getValue(),
				   name:obj.get(3).getValue(),
				   columnid:record.data.columnid
			   }
			});*/
        		var temp=obj.get(3).getValue();
        		var tempid=obj.get(1).getValue();
        		for(var i=0,len=store.getCount();i<len;i++)
        			{
        			if(store.getAt(i).data.name==temp&&store.getAt(i).data.columnid!=tempid){
        				 Ext.MessageBox.show({
     						title : '操作失败',
     						msg : '存在重复记录!',
     						buttons : Ext.Msg.OK,
     						icon : Ext.MessageBox.ERROR

     					});
        				flag=false;
        				break;
        			}
        			}
        		return flag;
        	}
        }
    });
	function submitRow(url,record)
	{
		Ext.Ajax.request({
			   url: url,
			   method:'post',
			   success : function(request) {/*var message = request.responseText;alertpand(message)*/},
				failure : function(request) {Ext.Msg.alert("错误", "与后台联系的时候出现了问题");},
			   headers: {
			       'my-header': 'foo'
			   },
			   params: record
			});


	}

	var grid = new Ext.grid.GridPanel({
		cm : cm,
		sm : sm,
		clicksToEdit: 1,
		plugins: [editor],
		width:frame_center.getInnerWidth()-4,
		height:frame_center.getInnerHeight(),
		renderTo:'divLlist'+this.menuid,
		store : store,
		tbar : [{
			text : '添加',
			iconCls : 'table_add',
			handler : function() {
				 var Plant = grid.getStore().recordType;
	                var p = new Plant({
	                   columnid:null,
	                   datatype:'s',nullable:1,used:'1',dboprflag:1,systempretag:0,
	                   tablecode:tn
	                });
				grid.stopEditing();
                store.insert(0, p);
                grid.getView().refresh();
                grid.getSelectionModel().selectRow(0);
                editor.startEditing(0);
			}
		},{
			text : '删除',
			iconCls : 'table_delete',
			handler : function() {
				var record = grid.getSelectionModel().getSelections();
				if (record.length <= 0) {
						Ext.MessageBox.alert('提示', '请选择需要删除的记录!');
						return;
					}else if (record.length > 1) {
						Ext.MessageBox.alert('提示', '最多只能选择一行!');
						return;				
					}else if (record[0].data.systempretag==0) {
						Ext.MessageBox.alert('提示', '系统预设字段不可删除!');
						return;				
					} 
				Ext.MessageBox.confirm('提示','确定要删除么?',function(btn){
					if (btn == 'yes') {
						/*Ext.Ajax.request({
							   url: basepath+'../sysControl/system/SysDicColumnController/delete.do',
							   method:'post',
							   success : function(request) {var message = request.responseText;alertpand(message);store.reload()},
								failure : function(request) {Ext.Msg.alert("错误", "与后台联系的时候出现了问题");},
							   headers: {
							       'my-header': 'foo'
							   },
							   params: {columnid:record[0].data.columnid}
							});*/
						store.remove(record[0]);
						grid.getView().refresh();
					}
				})
			}
		},{
			text : '保存',
			iconCls : 'table_save',
			handler : function() {
				var param=[];
				for(var i=0,len=store.getCount();i<len;i++)
					{
							param.push(store.getAt(i).data);
					}
				
				Ext.Ajax.request({
				   url: basepath+'../sysControl/system/SysDicColumnController/mergeAll.do',
				   method:'post',
				   success : function(request) {var message = request.responseText;if(alertpand(message))store.reload();},
					failure : function(request) {Ext.Msg.alert("错误", "与后台联系的时候出现了问题");},
				   headers: {
				       'my-header': 'foo'
				   },
				   params: {
					   tablename:tn,
					   param:Ext.encode(param)	
				   }
				});
			}
		},{
			text : '关联表设置',
			iconCls : 'table_add',
			handler : function() {
				openwindow("关联表设置", basepath+"../sysControl/system/SysDicColumnController/updateSource.do",true);
			}
		},{
			text : '读取数据库字段',
			iconCls : 'table_daoru',
			handler : function() {
				var oldproxy=store.proxy;
				store.proxy=new Ext.data.HttpProxy({url:'../sysControl/system/SysDicColumnController/readTable.do'});

				//store.proxy.url=basepath+;
				store.load({callback :function(){store.proxy=oldproxy}});
			}
		},{
			text : '刷新',
			iconCls : 'table_refresh',
			handler : function() {
				grid.getStore().reload();
			}
		},'->',
		{xtype:'closePage'}
		]
	});
	destroyResize(grid,
			destroyObjs);
	


}
